package com.four.controller;

import com.four.pojo.Category;
import com.four.pojo.Product;
import com.four.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author version v1.0
 * @ClassName：
 * @Description：
 **/
@Controller
public class CategoryController {
   @Autowired
   @Qualifier("categoryService")
    private ICategoryService iCategoryService;
   @RequestMapping("/findAllCateGory")
   public String findAllCateGory(Model model){
       List<Category> list=iCategoryService.findAllCateGory();
       model.addAttribute("list",list);
       return "goods_CLassify.jsp";
   }
   @RequestMapping("/addCateGory")
   public String addCateGory(Category category){
       iCategoryService.addCateGory(category);
       return "redirect:findAllCateGory";
   }
   @RequestMapping("/findByCateGoryId")
   public String findByCateGoryId(Model model,int cid){
       Category category=iCategoryService.findByCateGoryId(cid);
       model.addAttribute("category",category);
       return "edit_Classify.jsp";
   }
    @RequestMapping("/deleteCateGory")
    public String deleteCateGory(int cid){
//        Category category=new Category();
//        category.setCid(id);
        iCategoryService.deleteCateGory(cid);
        return "redirect:findAllCateGory";
    }
    @RequestMapping("/updateCateGory")
    public String updateCateGory(Category category){
        System.out.println(category.toString());
        iCategoryService.updateCateGory(category);
        return "redirect:findAllCateGory";
    }
}
